//
//  MenuShowAnimationView.swift
//  SwiftUIDemo
//
//  Created by zhouzuosong on 2020/8/20.
//  Copyright © 2020 Kael. All rights reserved.
//

import SwiftUI

struct MenuShowAnimationView: View {
    @State var showMenu = false
    
    @State var RSpace = 150.0 * 0.7;
    @State var BRSpace = 110.0 * 0.7;
    
    var body: some View {
        ZStack(alignment: .bottomTrailing) {
            VStack {
                Text("菜单动画")
                Spacer()
            }
                .frame(maxWidth: .infinity)

            
            Group{
                Button(action: {}, label: {
                    Image(systemName: "bag.badge.plus")
                        .padding(24)
                        .rotationEffect(Angle.degrees(showMenu ? 0 : -90))
                        .foregroundColor(.white)

                        
                })
                .background(Circle().fill(Color.green).shadow(radius: 8, x: 4, y: 4))
                .offset(x: 0, y: self.showMenu ? CGFloat(-RSpace) : 0)
                .opacity(showMenu ? 1 : 0)
                
                Button(action: {   }, label: {
                    Image(systemName: "gauge.badge.plus")
                        .padding(24)
                        .rotationEffect(Angle.degrees(showMenu ? 0 : -90))
                        .foregroundColor(.white)

                        
                })
                .background(Circle().fill(Color.green).shadow(radius: 8, x: 4, y: 4))
                .offset(x: showMenu ? CGFloat(-BRSpace) : 0, y: showMenu ? CGFloat(-BRSpace) : 0)
                .opacity(showMenu ? 1 : 0)
                
                Button(action: {   }, label: {
                    Image(systemName: "calendar.badge.plus")
                        .padding(24)
                        .rotationEffect(Angle.degrees(showMenu ? 0 : 90))
                        .foregroundColor(.white)

                        
                })
                .background(Circle().fill(Color.green).shadow(radius: 8, x: 4, y: 4))
                .offset(x: showMenu ? CGFloat(-RSpace) : 0, y:0)
                .opacity(showMenu ? 1 : 0)
                
                Button(action: { self.showMenu.toggle() }, label: {
                    Image(systemName: "plus")
                        .padding(24)
                        .rotationEffect(Angle.degrees(showMenu ? 45 : 0))
                        .foregroundColor(.white)

                })
                .background(Circle().fill(Color.green).shadow(radius: 8, x: 4, y: 4))
                
            }
                .padding(.trailing, 20)
                .animation(.default)
            
        }
    }
}

struct MenuShowAnimationView_Previews: PreviewProvider {
    static var previews: some View {
        MenuShowAnimationView()
    }
}
